package nmf;

import java.util.ArrayList;

import org.ejml.simple.SimpleMatrix;

public class SimpleFeatureSelectionNMFTool extends FeatureRelevanceTool {
   @Override
   public int getNumIterations(final SimpleMatrix V) {
      return 1;
   }
   
   @Override
   public Integer[] getRelevantFeatures(final SimpleMatrix V, final int category,
         final int numberOfFeatures) {
      final Integer[] relevantFeatures = new Integer[numberOfFeatures];
      final Double[] wordRankings = new Double[V.numRows()];
      
      for (int currentRowNumV = 0; currentRowNumV < V.numRows(); currentRowNumV++) {
         wordRankings[currentRowNumV] = getWordRelevance(V, currentRowNumV,
               category);
      }
      
      final ArrayList<Integer> indicesTaken = new ArrayList<Integer>();
      int currentMaxNdx = 0;
      
      for (int nthLargest = 1; nthLargest <= numberOfFeatures; nthLargest++) {
         currentMaxNdx = -1;
         double currentMax = -1;
         for (int currentRow = 0; currentRow < wordRankings.length; currentRow++) {
            if (!indicesTaken.contains(currentRow) && currentMax < wordRankings[currentRow]) {
               currentMaxNdx = currentRow;
               currentMax = wordRankings[currentRow];
            }
         }
         indicesTaken.add(currentMaxNdx);
      }
      
      indicesTaken.toArray(relevantFeatures);
      
      return relevantFeatures;
   }
}
